Ext.onReady(function(){ 

Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'under';

var addCurrencyStore=new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'showType.do?type=Currency',
method:'GET'
}), 
reader:new Ext.data.JsonReader({ },[
{name:'name'}, 
{name:'code'}
]) ,
autoLoad:true
}); 

var addCustTypeStore=new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'showType.do?type=CustType',
method:'GET'
}), 
reader:new Ext.data.JsonReader({ },[
{name:'name'}, 
{name:'code'}
]) 
,
autoLoad:true
}); 

var addBelongTypeStore=new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'showType.do?type=BelongType',
method:'GET'
}), 
reader:new Ext.data.JsonReader({ },[
{name:'name'}, 
{name:'code'}
]) ,
autoLoad:true
}); 

var addOrgTypeStore=new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'showType.do?type=OrgType',
method:'GET'
}), 
reader:new Ext.data.JsonReader({ },[
{name:'name'}, 
{name:'code'}
]) ,
autoLoad:true
}); 

var addCustStatusStore=new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'showType.do?type=CustStatus',
method:'GET'
}), 
reader:new Ext.data.JsonReader({ },[
{name:'name'}, 
{name:'code'}
]) ,
autoLoad:true
}); 

var addCustScopeStore=new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'showType.do?type=CustScope',
method:'GET'
}), 
reader:new Ext.data.JsonReader({ },[
{name:'name'}, 
{name:'code'}
]) ,
autoLoad:true
});

var addIndustryTypeStore=new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'showType.do?type=IndustryType',
method:'GET'
}), 
reader:new Ext.data.JsonReader({ },[
{name:'name'}, 
{name:'code'}
]) ,
autoLoad:true
}); 

//客户基本信息
var addForm = new Ext.form.FormPanel({ 
id: 'addForm', 
title: '限额参数', 
renderTo:"list",
height: 460, 
//样式 
bodyStyle: 'margin:5px;text-align:left;padding:5px 60px;', 
frame: true, 
xtype: 'filedset', 
labelWidth: 120, 
items: 
[ { xtype: 'fieldset', 
collapsible: true, 
autoHeight: true, 
autoWidth: true, 
items: 
[
	
{layout : "form",
	items : [	{ 
		xtype: 'combo', 
 			id : "custType",
              store :addCustTypeStore,
              fieldLabel: '客户类型',
              valueField : 'code',
              displayField : 'name',
              typeAhead : true,
              width: 200,
              mode:'remote', 
              emptyText : '请选择客户类型...',
             // editable: false,
		   	  readOnly:true,
              triggerAction : 'all',
              selectOnFocus : true,
              hiddenName:'custType'
	}]},
	
{layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
xtype: 'textfield', 
	id:'custName',
	name: 'custName', 
	fieldLabel: '客户名称', 
	readOnly:true,
	width: 200
}
]},{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
xtype: 'textfield', 
	id:'simpleName',
	name: 'simpleName', 
	fieldLabel: '客户简称', 
	width: 200
}
]} 
]},{
layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
			xtype: 'textfield', 
		id:'busiLicenseId',
		name: 'busiLicenseId', 
		fieldLabel: '营业执照代码', 
		readOnly:true,
		width: 200 
}
]},{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
xtype: 'textfield', 
	id:'organizationId',
	name: 'organizationId', 
	fieldLabel: '组织结构代码', 
	readOnly:true,
	width: 200 
}
]} 
]},
{
layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
		xtype: 'textfield', 
		id:'englishName',
		name: 'englishName', 
		fieldLabel: '客户名称(英文)', 
		width: 200
}
]},{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
		xtype: 'textfield', 
		id:'simpleEnName',
		name: 'simpleEnName', 
		fieldLabel: '客户简称(英文)', 
		width: 200
}
]} 
]},

{
layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
	xtype: 'combo', 
 id : "belongType",
              store :addBelongTypeStore,
              fieldLabel: '所有制类别',
              valueField : 'code',
              displayField : 'name',
              typeAhead : true,
              width: 200,
              mode:'remote', 
              emptyText : '请选择所有制类别...',
              editable: false,
              triggerAction : 'all',
              selectOnFocus : true,
              hiddenName:'belongType'
}
]},{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
	xtype: 'combo', 
 id : "orgType",
              store :addOrgTypeStore,
            fieldLabel: '组织类别',
              valueField : 'code',
              displayField : 'name',
              emptyText : '请选择组织类别...',
              editable: false,
              typeAhead : true,
              width: 200,
              mode:'remote',  
              triggerAction : 'all',
              selectOnFocus : true,
              hiddenName:'orgType'
}
]} 
]},

{
layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
           xtype: 'datefield',
			id: 'establishDate', 
			name: 'establishDate', 
			fieldLabel: '成立时间',
			allowBlank: true,
			editable:false,  
			format : 'Y-m-d' ,
			width: 200
}
]},{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
           xtype: 'datefield',
			id: 'closeDate', 
			name: 'closeDate', 
			fieldLabel: '财年截止日期',
			allowBlank: true,
			editable:false,  
			format : 'Y-m-d' ,
			width: 200
}
]} 
]},

{
layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
          xtype: 'textfield', 
		id:'registercapital',
		name: 'registercapital', 
		fieldLabel: '注册资本', 
		regex:/^[0-9]+\.{0,1}[0-9]{0,2}$/,
 		regexText:'只能输入整数或小数！' , 
		width: 200
}
]},{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
          xtype: 'combo', 
 			id : "capitalCurrency",
              store :addCurrencyStore,
            fieldLabel: '币种',
              valueField : 'code',
              displayField : 'name',
              emptyText : '请选择币种...',
              editable: false,
              typeAhead : true,
              width: 200,
              mode:'remote',  
              triggerAction : 'all',
              selectOnFocus : true,
              hiddenName:'capitalCurrency'
}
]} 
]},

{ layout : "form",
           items : [{
			xtype: 'textfield', 
			id:'receiveRate',
			name: 'receiveRate', 
			fieldLabel: '注册资本到位率(%)', 
			regex:/^[0-9]+\.{0,1}[0-9]{0,2}$/,
 			regexText:'请输入正确格式' , 
			width: 200
              
}]},{layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
			xtype: 'combo', 
			 id : "custScope",
              store :addCustScopeStore,
              fieldLabel: '企业规模',
              valueField : 'code',
              displayField : 'name',
              typeAhead : true,
              width: 200,
              mode:'remote', 
              emptyText : '请选择企业规模...',
              editable: false,
              triggerAction : 'all',
              selectOnFocus : true,
              hiddenName:'custScope'
}
]},{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
				xtype: 'combo', 
		 		id : "IndustryType",
              store :addIndustryTypeStore,
              fieldLabel: '行业类型',
              valueField : 'code',
              displayField : 'name',
              typeAhead : true,
              width: 200,
              mode:'remote', 
              emptyText : '请选择行业类型...',
              editable: false,
              triggerAction : 'all',
              selectOnFocus : true,
              hiddenName:'industryType'
}
]} 
]},
{ layout : "form",
           items : [{
			xtype: 'combo', 
			 id : "custStatus",
              store :addCustStatusStore,
              fieldLabel: '客户状态',
              valueField : 'code',
              displayField : 'name',
              typeAhead : true,
              width: 200,
              mode:'remote', 
              emptyText : '请选择客户状态...',
              editable: false,
              triggerAction : 'all',
              selectOnFocus : true,
              hiddenName:'custStatus'
              
}]}

] 
}],
buttonAlign:'right',
buttons: 
[  
{ text: '保存', handler: editFunction } ,
{ text: '下一步', handler: editFunctionAndNext }
] 
});


//表单加载数据
addForm.form.load({  
    //waitMsg : '正在加载数据请稍后',
    //waitTitle : '提示',
    url : 'customer/getGeneral.do', 
    method:'post',
    success:function(form,action){
    	
    },  
    failure:function(form,action){
     //Ext.Msg.alert('提示','数据加载失败');  
    }  
});

function editFunction(){

	if(addForm.form.isValid()){
		addForm.form.doAction('submit', { 
			url : 'customer/editGeneral.do', 
			method : 'post', 
			success : function() {
				Ext.Msg.alert('提示', '保存成功！'); 
			}, 
			failure : function() { 
				Ext.Msg.alert('提示', '保存失败！'); 
			} 
		}); 
	}
	
}

function editFunctionAndNext(){
	if(addForm.form.isValid()){
		addForm.form.doAction('submit', { 
			url : 'customer/editGeneral.do', 
			method : 'post', 
			success : function() {
				Ext.Msg.confirm("Confirm",'保存成功，是否继续添加地址信息',function(bool){
					if(bool=='yes'){
						window.location.href = "view/customer/Customer_Address.jsp";
						return true;
					}
					else{
						return false;	
					}
				}); 
				//alert("成功");
				
			}, 
			failure : function() { 
				Ext.Msg.alert('提示', '编辑失败！'); 
			} 
		}); 
	}
}
       
}); 